package com.jeasonzhao.report.model.chart;

import com.jeasonzhao.model.Model;
import com.jeasonzhao.model.ModelField;
import com.jeasonzhao.report.dataset.DataSet;
import com.jeasonzhao.report.exceptions.SQLReportException;
import com.jeasonzhao.report.exceptions.RenderException;
import com.jeasonzhao.report.model.BaseReportModelItem;

/**
 * Ugly model, if you add some new properties into this class,
 * remember that you should add some code into the "copy construct"
 * to make sure those properties effect.
 * I do not use the default copy construct, because it it not safe enough.
 */
@Model("chart")
public class Chart extends BaseReportModelItem
{
    private static final long serialVersionUID = 1L;

    @ModelField(names = "title,name")
    private String m_strTitle = null;

    @ModelField(names = "row,rowIndex,rowNum")
    private int m_nRowIndex = 0;

    @ModelField(names = "height,h")
    private String m_strHeight = null;

    @ModelField(names = "width,w")
    private String m_strWidth = null;

    @ModelField(collection = true,names = "series")
    private DataSeriesCollection m_dataSeries = null;

    @ModelField(names = "show3D,show3DView,view3D")
    private boolean m_isShow3D = true;

    @ModelField(names = "theme,themeName,Style")
    private String m_strChartTheme = null;

    @ModelField(names = "border,borderThickness")
    private int m_BorderThickness = 0;

    @ModelField(names = "animation,animationDuration")
    private int m_AnimationDuration = 5;

    @ModelField(names = "animationType")
    private String m_AnimationType = null;

    @ModelField(names = "color,clr")
    private ColorSets colorSet = null;

    @ModelField(names = "cursor,cur")
    private Cursors cursor = null;

    public Chart()
    {
    }

    public String getTheme()
    {
        return null == m_strChartTheme || m_strChartTheme.trim().length() < 1 ? null : m_strChartTheme;
    }

    public String getAnimationType()
    {
        return null == m_AnimationType || m_AnimationType.trim().length() < 1 ? null : m_AnimationType;
    }

    public int getBorderThickness()
    {
        return m_BorderThickness;
    }

    public int getAnimationDuration()
    {
        return m_AnimationDuration;
    }

    public boolean isShow3DView()
    {
        return m_isShow3D;
    }

    public boolean isAnimationEnabled()
    {
        return m_AnimationDuration > 0;
    }

    public String toString()
    {
        return null == m_dataSeries ? "" : m_dataSeries.toString();
    }

    public Chart(Chart c)
    {
        if(c == null)
        {
            return;
        }
        this.m_dataSeries = new DataSeriesCollection(c.m_dataSeries);
        this.m_nRowIndex = c.m_nRowIndex;
        this.m_strHeight = c.m_strHeight;
        this.m_strWidth = c.m_strWidth;
        this.m_strTitle = c.m_strTitle;

        this.m_isShow3D = c.m_isShow3D;
        this.m_strChartTheme = c.m_strChartTheme;
        this.m_BorderThickness = c.m_BorderThickness;
        this.m_AnimationDuration = c.m_AnimationDuration;
        this.m_AnimationType = c.m_AnimationType;

        this.colorSet = c.colorSet;
        this.cursor = c.cursor;
    }

    public String getTitle()
    {
        return m_strTitle == null || m_strTitle.trim().length() < 1 ? null : m_strTitle;
    }

    public void setTitle(String v)
    {
        m_strTitle = v;
    }

    public int getRowIndex()
    {
        return m_nRowIndex;
    }

    public void setRowIndex(int v)
    {
        m_nRowIndex = v;
    }

    public String getHeight()
    {
        return m_strHeight == null || m_strHeight.trim().length() < 1 ? null : m_strHeight;
    }

    public void setHeight(String v)
    {
        m_strHeight = v;
    }

    public String getWidth()
    {
        return m_strWidth == null || m_strWidth.trim().length() < 1 ? null : m_strWidth;
    }

    public void setWidth(String v)
    {
        m_strWidth = v;
    }

    public DataSeriesCollection getDataSeries()
    {
        return m_dataSeries;
    }

    public void setDataSeries(DataSeriesCollection v)
    {
        m_dataSeries = v;
    }

    public void initDataSet(DataSet dataset)
        throws RenderException
    {
        for(int n = 0;null != m_dataSeries && n < m_dataSeries.size();n++)
        {
            try
            {
                m_dataSeries.get(n).initDataSet(dataset);
            }
            catch(SQLReportException ex)
            {
            }
        }
    }

    public ColorSets getColorSet()
    {
        return colorSet;
    }

    public Cursors getCursor()
    {
        return cursor;
    }

    public void setColorSet(ColorSets colorSet)
    {
        this.colorSet = colorSet;
    }

    public void setCursor(Cursors cursor)
    {
        this.cursor = cursor;
    }

}
